<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Linux命令," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径。当然每次数据包由某一同样的出发点（source）到达某一同样的目的地(destination)走的路径可能会不一样，但基本上来说大部分时候所走的路由是相同的。linux系统中，我们称之为traceroute,在MS">
<meta name="keywords" content="Linux命令">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux 命令- traceroute">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/57. Linux 命令- traceroute/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径。当然每次数据包由某一同样的出发点（source）到达某一同样的目的地(destination)走的路径可能会不一样，但基本上来说大部分时候所走的路由是相同的。linux系统中，我们称之为traceroute,在MS">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-01T08:37:11.473Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux 命令- traceroute">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径。当然每次数据包由某一同样的出发点（source）到达某一同样的目的地(destination)走的路径可能会不一样，但基本上来说大部分时候所走的路由是相同的。linux系统中，我们称之为traceroute,在MS">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/57. Linux 命令- traceroute/"/>





  <title>Linux 命令- traceroute | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/57. Linux 命令- traceroute/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Linux 命令- traceroute</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T01:57:34+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径。当然每次数据包由某一同样的出发点（source）到达某一同样的目的地(destination)走的路径可能会不一样，但基本上来说大部分时候所走的路由是相同的。linux系统中，我们称之为traceroute,在MS Windows中为tracert。 traceroute通过发送小的数据包到目的设备直到其返回，来测量其需要多长时间。一条路径上的每个设备traceroute要测3次。输出结果中包括每次测试的时间(ms)和设备的名称（如有的话）及其IP地址。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在大多数情况下，我们会在linux主机系统下，直接执行命令行：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">traceroute hostname</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;而在Windows系统下是执行tracert的命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tracert hostname</div></pre></td></tr></table></figure>
<h2 id="1-命令格式"><a href="#1-命令格式" class="headerlink" title="1.命令格式"></a>1.命令格式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">traceroute [参数] [主机]</div></pre></td></tr></table></figure>
<h2 id="2-命令功能"><a href="#2-命令功能" class="headerlink" title="2.命令功能"></a>2.命令功能</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;traceroute指令让你追踪网络数据包的路由途径，预设数据包大小是40Bytes，用户可另行设置。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;具体参数格式：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">traceroute [-dFlnrvx][-f&lt;存活数值&gt;][-g&lt;网关&gt;...][-i&lt;网络界面&gt;][-m&lt;存活数值&gt;][-p&lt;通信端口&gt;][-s&lt;来源地址&gt;][-t&lt;服务类型&gt;][-w&lt;超时秒数&gt;][主机名称或IP地址][数据包大小]</div></pre></td></tr></table></figure>
<h2 id="3-命令参数"><a href="#3-命令参数" class="headerlink" title="3.命令参数"></a>3.命令参数</h2><ul>
<li>-d 使用Socket层级的排错功能。</li>
<li>-f 设置第一个检测数据包的存活数值TTL的大小。</li>
<li>-F 设置勿离断位。</li>
<li>-g 设置来源路由网关，最多可设置8个。</li>
<li>-i 使用指定的网络界面送出数据包。</li>
<li>-I 使用ICMP回应取代UDP资料信息。</li>
<li>-m 设置检测数据包的最大存活数值TTL的大小。</li>
<li>-n 直接使用IP地址而非主机名称。</li>
<li>-p 设置UDP传输协议的通信端口。</li>
<li>-r 忽略普通的Routing Table，直接将数据包送到远端主机上。</li>
<li>-s 设置本地主机送出数据包的IP地址。</li>
<li>-t 设置检测数据包的TOS数值。</li>
<li>-v 详细显示指令的执行过程。</li>
<li>-w 设置等待远端主机回报的时间。</li>
<li>-x 开启或关闭数据包的正确性检验。</li>
</ul>
<h2 id="4-使用实例"><a href="#4-使用实例" class="headerlink" title="4.使用实例"></a>4.使用实例</h2><h3 id="实例1：traceroute-用法简单、最常用的用法"><a href="#实例1：traceroute-用法简单、最常用的用法" class="headerlink" title="实例1：traceroute 用法简单、最常用的用法"></a>实例1：traceroute 用法简单、最常用的用法</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">traceroute www.baidu.com</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]# traceroute www.baidu.com</div><div class="line">traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets</div><div class="line"> 1  192.168.74.2 (192.168.74.2)  2.606 ms  2.771 ms  2.950 ms</div><div class="line"> 2  211.151.56.57 (211.151.56.57)  0.596 ms  0.598 ms  0.591 ms</div><div class="line"> 3  211.151.227.206 (211.151.227.206)  0.546 ms  0.544 ms  0.538 ms</div><div class="line"> 4  210.77.139.145 (210.77.139.145)  0.710 ms  0.748 ms  0.801 ms</div><div class="line"> 5  202.106.42.101 (202.106.42.101)  6.759 ms  6.945 ms  7.107 ms</div><div class="line"> 6  61.148.154.97 (61.148.154.97)  718.908 ms * bt-228-025.bta.net.cn (202.106.228.25)  5.177 ms</div><div class="line"> 7  124.65.58.213 (124.65.58.213)  4.343 ms  4.336 ms  4.367 ms</div><div class="line"> 8  202.106.35.190 (202.106.35.190)  1.795 ms 61.148.156.138 (61.148.156.138)  1.899 ms  1.951 ms</div><div class="line"> 9  * * *</div><div class="line">30  * * *</div><div class="line">[root@localhost ~]#</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;记录按序列号从1开始，每个纪录就是一跳 ，每跳表示一个网关，我们看到每行有三个时间，单位是 ms，其实就是-q的默认参数。探测数据包向每个网关发送三个数据包后，网关响应后返回的时间；如果您用 traceroute -q 4 www.58.com ，表示向每个网关发送4个数据包。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;有时我们traceroute 一台主机时，会看到有一些行是以星号表示的。出现这样的情况，可能是防火墙封掉了ICMP的返回信息，所以我们得不到什么相关的数据包返回数据。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;有时我们在某一网关处延时比较长，有可能是某台网关比较阻塞，也可能是物理设备本身的原因。当然如果某台DNS出现问题时，不能解析主机名、域名时，也会 有延时长的现象；您可以加-n 参数来避免DNS解析，以IP格式输出数据。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果在局域网中的不同网段之间，我们可以通过traceroute 来排查问题所在，是主机的问题还是网关的问题。如果我们通过远程来访问某台服务器遇到问题时，我们用到traceroute 追踪数据包所经过的网关，提交IDC服务商，也有助于解决问题；但目前看来在国内解决这样的问题是比较困难的，就是我们发现问题所在，IDC服务商也不可能帮助我们解决。</p>
<h3 id="实例2：跳数设置"><a href="#实例2：跳数设置" class="headerlink" title="实例2：跳数设置"></a>实例2：跳数设置</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">traceroute -m 10 www.baidu.com</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># traceroute -m 10 www.baidu.com</span></div><div class="line">traceroute to www.baidu.com (61.135.169.105), 10 hops max, 40 byte packets</div><div class="line"> 1  192.168.74.2 (192.168.74.2)  1.534 ms  1.775 ms  1.961 ms</div><div class="line"> 2  211.151.56.1 (211.151.56.1)  0.508 ms  0.514 ms  0.507 ms</div><div class="line"> 3  211.151.227.206 (211.151.227.206)  0.571 ms  0.558 ms  0.550 ms</div><div class="line"> 4  210.77.139.145 (210.77.139.145)  0.708 ms  0.729 ms  0.785 ms</div><div class="line"> 5  202.106.42.101 (202.106.42.101)  7.978 ms  8.155 ms  8.311 ms</div><div class="line"> 6  bt-228-037.bta.net.cn (202.106.228.37)  772.460 ms bt-228-025.bta.net.cn (202.106.228.25)  2.152 ms 61.148.154.97 (61.148.154.97)  772.107 ms</div><div class="line"> 7  124.65.58.221 (124.65.58.221)  4.875 ms 61.148.146.29 (61.148.146.29)  2.124 ms 124.65.58.221 (124.65.58.221)  4.854 ms</div><div class="line"> 8  123.126.6.198 (123.126.6.198)  2.944 ms 61.148.156.6 (61.148.156.6)  3.505 ms 123.126.6.198 (123.126.6.198)  2.885 ms</div><div class="line"> 9  * * *</div><div class="line">10  * * *</div><div class="line">[root@localhost ~]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例3：显示IP地址，不查主机名"><a href="#实例3：显示IP地址，不查主机名" class="headerlink" title="实例3：显示IP地址，不查主机名"></a>实例3：显示IP地址，不查主机名</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">traceroute -n www.baidu.com</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># traceroute -n www.baidu.com</span></div><div class="line">traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets</div><div class="line"> 1  211.151.74.2  5.430 ms  5.636 ms  5.802 ms</div><div class="line"> 2  211.151.56.57  0.627 ms  0.625 ms  0.617 ms</div><div class="line"> 3  211.151.227.206  0.575 ms  0.584 ms  0.576 ms</div><div class="line"> 4  210.77.139.145  0.703 ms  0.754 ms  0.806 ms</div><div class="line"> 5  202.106.42.101  23.683 ms  23.869 ms  23.998 ms</div><div class="line"> 6  202.106.228.37  247.101 ms * *</div><div class="line"> 7  61.148.146.29  5.256 ms 124.65.58.213  4.386 ms  4.373 ms</div><div class="line"> 8  202.106.35.190  1.610 ms 61.148.156.138  1.786 ms 61.148.3.34  2.089 ms</div><div class="line"> 9  * * *</div><div class="line">30  * * *</div><div class="line">[root@localhost ~]<span class="comment"># traceroute www.baidu.com</span></div><div class="line">traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets</div><div class="line"> 1  211.151.74.2 (211.151.74.2)  4.671 ms  4.865 ms  5.055 ms</div><div class="line"> 2  211.151.56.57 (211.151.56.57)  0.619 ms  0.618 ms  0.612 ms</div><div class="line"> 3  211.151.227.206 (211.151.227.206)  0.620 ms  0.642 ms  0.636 ms</div><div class="line"> 4  210.77.139.145 (210.77.139.145)  0.720 ms  0.772 ms  0.816 ms</div><div class="line"> 5  202.106.42.101 (202.106.42.101)  7.667 ms  7.910 ms  8.012 ms</div><div class="line"> 6  bt-228-025.bta.net.cn (202.106.228.25)  2.965 ms  2.440 ms 61.148.154.97 (61.148.154.97)  431.337 ms</div><div class="line"> 7  124.65.58.213 (124.65.58.213)  5.134 ms  5.124 ms  5.044 ms</div><div class="line"> 8  202.106.35.190 (202.106.35.190)  1.917 ms  2.052 ms  2.059 ms</div><div class="line"> 9  * * *</div><div class="line">30  * * *</div><div class="line">[root@localhost ~]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例4：探测包使用的基本UDP端口设置6888"><a href="#实例4：探测包使用的基本UDP端口设置6888" class="headerlink" title="实例4：探测包使用的基本UDP端口设置6888"></a>实例4：探测包使用的基本UDP端口设置6888</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">traceroute -p 6888 www.baidu.com</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># traceroute -p 6888 www.baidu.com</span></div><div class="line">traceroute to www.baidu.com (220.181.111.147), 30 hops max, 40 byte packets</div><div class="line"> 1  211.151.74.2 (211.151.74.2)  4.927 ms  5.121 ms  5.298 ms</div><div class="line"> 2  211.151.56.1 (211.151.56.1)  0.500 ms  0.499 ms  0.509 ms</div><div class="line"> 3  211.151.224.90 (211.151.224.90)  0.637 ms  0.631 ms  0.641 ms</div><div class="line"> 4  * * *</div><div class="line"> 5  220.181.70.98 (220.181.70.98)  5.050 ms  5.313 ms  5.596 ms</div><div class="line"> 6  220.181.17.94 (220.181.17.94)  1.665 ms !X * *</div><div class="line">[root@localhost ~]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例5：把探测包的个数设置为值4"><a href="#实例5：把探测包的个数设置为值4" class="headerlink" title="实例5：把探测包的个数设置为值4"></a>实例5：把探测包的个数设置为值4</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">traceroute -q 4 www.baidu.com</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># traceroute -q 4 www.baidu.com</span></div><div class="line">traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets</div><div class="line"> 1  211.151.74.2 (211.151.74.2)  40.633 ms  40.819 ms  41.004 ms  41.188 ms</div><div class="line"> 2  211.151.56.57 (211.151.56.57)  0.637 ms  0.633 ms  0.627 ms  0.619 ms</div><div class="line"> 3  211.151.227.206 (211.151.227.206)  0.505 ms  0.580 ms  0.571 ms  0.569 ms</div><div class="line"> 4  210.77.139.145 (210.77.139.145)  0.753 ms  0.800 ms  0.853 ms  0.904 ms</div><div class="line"> 5  202.106.42.101 (202.106.42.101)  7.449 ms  7.543 ms  7.738 ms  7.893 ms</div><div class="line"> 6  61.148.154.97 (61.148.154.97)  316.817 ms bt-228-025.bta.net.cn (202.106.228.25)  3.695 ms  3.672 ms *</div><div class="line"> 7  124.65.58.213 (124.65.58.213)  3.056 ms  2.993 ms  2.960 ms 61.148.146.29 (61.148.146.29)  2.837 ms</div><div class="line"> 8  61.148.3.34 (61.148.3.34)  2.179 ms  2.295 ms  2.442 ms 202.106.35.190 (202.106.35.190)  7.136 ms</div><div class="line"> 9  * * * *</div><div class="line">30  * * * *</div><div class="line">[root@localhost ~]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例6：绕过正常的路由表，直接发送到网络相连的主机"><a href="#实例6：绕过正常的路由表，直接发送到网络相连的主机" class="headerlink" title="实例6：绕过正常的路由表，直接发送到网络相连的主机"></a>实例6：绕过正常的路由表，直接发送到网络相连的主机</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">traceroute -r www.baidu.com</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># traceroute -r www.baidu.com</span></div><div class="line">traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets</div><div class="line">connect: 网络不可达</div><div class="line">[root@localhost ~]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例7：把对外发探测包的等待响应时间设置为3秒"><a href="#实例7：把对外发探测包的等待响应时间设置为3秒" class="headerlink" title="实例7：把对外发探测包的等待响应时间设置为3秒"></a>实例7：把对外发探测包的等待响应时间设置为3秒</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">traceroute -w 3 www.baidu.com</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># traceroute -w 3 www.baidu.com</span></div><div class="line">traceroute to www.baidu.com (61.135.169.105), 30 hops max, 40 byte packets</div><div class="line"> 1  211.151.74.2 (211.151.74.2)  2.306 ms  2.469 ms  2.650 ms</div><div class="line"> 2  211.151.56.1 (211.151.56.1)  0.621 ms  0.613 ms  0.603 ms</div><div class="line"> 3  211.151.227.206 (211.151.227.206)  0.557 ms  0.560 ms  0.552 ms</div><div class="line"> 4  210.77.139.145 (210.77.139.145)  0.708 ms  0.761 ms  0.817 ms</div><div class="line"> 5  202.106.42.101 (202.106.42.101)  7.520 ms  7.774 ms  7.902 ms</div><div class="line"> 6  bt-228-025.bta.net.cn (202.106.228.25)  2.890 ms  2.369 ms 61.148.154.97 (61.148.154.97)  471.961 ms</div><div class="line"> 7  124.65.58.221 (124.65.58.221)  4.490 ms  4.483 ms  4.472 ms</div><div class="line"> 8  123.126.6.198 (123.126.6.198)  2.948 ms 61.148.156.6 (61.148.156.6)  7.688 ms  7.756 ms</div><div class="line"> 9  * * *</div><div class="line">30  * * *</div><div class="line">[root@localhost ~]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h2 id="Traceroute的工作原理："><a href="#Traceroute的工作原理：" class="headerlink" title="Traceroute的工作原理："></a>Traceroute的工作原理：</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Traceroute最简单的基本用法是：traceroute hostname</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Traceroute程序的设计是利用ICMP及IP header的TTL（Time To Live）栏位（field）。首先，traceroute送出一个TTL是1的IP datagram（其实，每次送出的为3个40字节的包，包括源地址，目的地址和包发出的时间标签）到目的地，当路径上的第一个路由器（router）收到这个datagram时，它将TTL减1。此时，TTL变为0了，所以该路由器会将此datagram丢掉，并送回一个「ICMP time exceeded」消息（包括发IP包的源地址，IP包的所有内容及路由器的IP地址），traceroute 收到这个消息后，便知道这个路由器存在于这个路径上，接着traceroute 再送出另一个TTL是2 的datagram，发现第2 个路由器…… traceroute 每次将送出的datagram的TTL 加1来发现另一个路由器，这个重复的动作一直持续到某个datagram 抵达目的地。当datagram到达目的地后，该主机并不会送回ICMP time exceeded消息，因为它已是目的地了，那么traceroute如何得知目的地到达了呢？</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Traceroute在送出UDP datagrams到目的地时，它所选择送达的port number 是一个一般应用程序都不会用的号码（30000 以上），所以当此UDP datagram 到达目的地后该主机会送回一个「ICMP port unreachable」的消息，而当traceroute 收到这个消息时，便知道目的地已经到达了。所以traceroute 在Server端也是没有所谓的Daemon 程式。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Traceroute提取发 ICMP TTL到期消息设备的IP地址并作域名解析。每次 ，Traceroute都打印出一系列数据,包括所经过的路由设备的域名及 IP地址,三个包每次来回所花时间。</p>
<h2 id="windows之tracert"><a href="#windows之tracert" class="headerlink" title="windows之tracert:"></a>windows之tracert:</h2><h3 id="格式："><a href="#格式：" class="headerlink" title="格式："></a>格式：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name</div></pre></td></tr></table></figure>
<h3 id="参数说明："><a href="#参数说明：" class="headerlink" title="参数说明："></a>参数说明：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tracert [-d] [-h maximum_hops] [-j computer-list] [-w timeout] target_name</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;该诊断实用程序通过向目的地发送具有不同生存时间 (TL) 的 Internet 控制信息协议 (CMP) 回应报文，以确定至目的地的路由。路径上的每个路由器都要在转发该 ICMP 回应报文之前将其 TTL 值至少减 1，因此 TTL 是有效的跳转计数。当报文的 TTL 值减少到 0 时，路由器向源系统发回 ICMP 超时信息。通过发送 TTL 为 1 的第一个回应报文并且在随后的发送中每次将 TTL 值加 1，直到目标响应或达到最大 TTL 值，Tracert 可以确定路由。通过检查中间路由器发发回的 ICMP 超时 (ime Exceeded) 信息，可以确定路由器。注意，有些路由器“安静”地丢弃生存时间 (TLS) 过期的报文并且对 tracert 无效。</p>
<h4 id="参数："><a href="#参数：" class="headerlink" title="参数："></a>参数：</h4><ul>
<li>-d 指定不对计算机名解析地址。</li>
<li>-h maximum_hops 指定查找目标的跳转的最大数目。</li>
<li>-jcomputer-list 指定在 computer-list 中松散源路由。</li>
<li>-w timeout 等待由 timeout 对每个应答指定的毫秒数。</li>
<li>target_name 目标计算机的名称。</li>
</ul>
<h4 id="实例："><a href="#实例：" class="headerlink" title="实例："></a>实例：</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line">C:\Users\Administrator&gt;tracert www.58.com</div><div class="line"></div><div class="line">Tracing route to www.58.com [221.187.111.30]</div><div class="line">over a maximum of 30 hops:</div><div class="line"></div><div class="line">  1     1 ms     1 ms     1 ms  10.58.156.1</div><div class="line">  2     1 ms    &lt;1 ms    &lt;1 ms  10.10.10.1</div><div class="line">  3     1 ms     1 ms     1 ms  211.103.193.129</div><div class="line">  4     2 ms     2 ms     2 ms  10.255.109.129</div><div class="line">  5     1 ms     1 ms     3 ms  124.205.98.205</div><div class="line">  6     2 ms     2 ms     2 ms  124.205.98.253</div><div class="line">  7     2 ms     6 ms     1 ms  202.99.1.125</div><div class="line">  8     5 ms     6 ms     5 ms  118.186.0.113</div><div class="line">  9   207 ms     *        *     118.186.0.106</div><div class="line"> 10     8 ms     6 ms    11 ms  124.238.226.201</div><div class="line"> 11     6 ms     7 ms     6 ms  219.148.19.177</div><div class="line"> 12    12 ms    12 ms    16 ms  219.148.18.117</div><div class="line"> 13    14 ms    17 ms    16 ms  219.148.19.125</div><div class="line"> 14    13 ms    13 ms    12 ms  202.97.80.113</div><div class="line"> 15     *        *        *     Request timed out.</div><div class="line"> 16    12 ms    12 ms    17 ms  bj141-147-82.bjtelecom.net [219.141.147.82]</div><div class="line"> 17    13 ms    13 ms    12 ms  202.97.48.2</div><div class="line"> 18     *        *        *     Request timed out.</div><div class="line"> 19    14 ms    14 ms    12 ms  221.187.224.85</div><div class="line"> 20    15 ms    13 ms    12 ms  221.187.104.2</div><div class="line"> 21     *        *        *     Request timed out.</div><div class="line"> 22    15 ms    17 ms    18 ms  221.187.111.30</div><div class="line"></div><div class="line">Trace complete.</div></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Linux命令/" rel="tag"># Linux命令</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/41. Linux 命令- grep/" rel="next" title="Linux 命令- grep">
                <i class="fa fa-chevron-left"></i> Linux 命令- grep
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/33. Linux 命令-bz2/" rel="prev" title="Linux 命令- bz2">
                Linux 命令- bz2 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-命令格式"><span class="nav-number">1.</span> <span class="nav-text">1.命令格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-命令功能"><span class="nav-number">2.</span> <span class="nav-text">2.命令功能</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-命令参数"><span class="nav-number">3.</span> <span class="nav-text">3.命令参数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-使用实例"><span class="nav-number">4.</span> <span class="nav-text">4.使用实例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#实例1：traceroute-用法简单、最常用的用法"><span class="nav-number">4.1.</span> <span class="nav-text">实例1：traceroute 用法简单、最常用的用法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例2：跳数设置"><span class="nav-number">4.2.</span> <span class="nav-text">实例2：跳数设置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例3：显示IP地址，不查主机名"><span class="nav-number">4.3.</span> <span class="nav-text">实例3：显示IP地址，不查主机名</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例4：探测包使用的基本UDP端口设置6888"><span class="nav-number">4.4.</span> <span class="nav-text">实例4：探测包使用的基本UDP端口设置6888</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例5：把探测包的个数设置为值4"><span class="nav-number">4.5.</span> <span class="nav-text">实例5：把探测包的个数设置为值4</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例6：绕过正常的路由表，直接发送到网络相连的主机"><span class="nav-number">4.6.</span> <span class="nav-text">实例6：绕过正常的路由表，直接发送到网络相连的主机</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例7：把对外发探测包的等待响应时间设置为3秒"><span class="nav-number">4.7.</span> <span class="nav-text">实例7：把对外发探测包的等待响应时间设置为3秒</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Traceroute的工作原理："><span class="nav-number">5.</span> <span class="nav-text">Traceroute的工作原理：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#windows之tracert"><span class="nav-number">6.</span> <span class="nav-text">windows之tracert:</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#格式："><span class="nav-number">6.1.</span> <span class="nav-text">格式：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#参数说明："><span class="nav-number">6.2.</span> <span class="nav-text">参数说明：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#参数："><span class="nav-number">6.2.1.</span> <span class="nav-text">参数：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例："><span class="nav-number">6.2.2.</span> <span class="nav-text">实例：</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
